package com.haoge7777.weblog.web.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
@Profile("dev")  //只在dev环境中开启
public class Knife4jConfig {

    @Bean("webApi")
    public Docket createApiDoc(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(buildApiInfo())
                //分组名称
                .groupName("Web 前台接口")
                .select()
                //这里指定Controller扫描包的路径
                .apis(RequestHandlerSelectors.basePackage("com.haoge7777.weblog.web.controller"))
                .build();

        return docket;
    }

    /**
     * 构建API信息
     */
    private ApiInfo buildApiInfo(){
        return new ApiInfoBuilder()
                .title("Weblog 博客前台接口文档") //标题
                .description("Weblog 是一款由Spring Boot + Vue 3.2 + + Vite 4.3 开发的前后端分离博客") //描述
                .termsOfServiceUrl("https://www.haoge7777.com") //API服务条款
                .contact(new Contact("豪哥7777","https://www.haoge7777.com","3113371239@qq.com")) //API 服务条款
                .version("1.0") //版本
                .build();

    }


}
